using System.Linq;
using NUnit.Framework;
using SharpTestsEx;

namespace AltNetHispano.Vale.Tests.Example
{
	public class DeepValidationOfRelationsTest
	{
		[Test]
		public void WhenValidateContactThenShouldValidateItsAddress()
		{
			var validator = new Validator();
			
			validator.Register<Address>(p => validator.StringIsRequired("City", p.City));

			validator.Register<Contact>(cotact => validator.StringIsRequired("Nick name", cotact.NickName));
			validator.Register<Contact>(cotact => validator.GetInvalidMessages(cotact.Address).FirstOrDefault());

			var contact = new Contact {NickName = "blha", Address = new Address {City = null}};
			validator.IsValid(contact).Should().Be.False();
		}

		[Test]
		public void WhenContactAndAddressAreValidThenContactIsValid()
		{
			var validator = new Validator();

			validator.Register<Address>(p => validator.StringIsRequired("City", p.City));

			validator.Register<Contact>(p => validator.StringIsRequired("Nick name", p.NickName));
			validator.Register<Contact>(p => validator.GetInvalidMessages(p.Address).FirstOrDefault());

			var contact = new Contact { NickName = "blha", Address = new Address { City = "Buenos Aires" } };
			validator.IsValid(contact).Should().Be.True();
		}
	}
}